package com.viphuli.app.tool.fragment;

import java.util.ArrayList;
import java.util.List;

import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import butterknife.Bind;

import com.loopj.android.http.RequestParams;
import com.viphuli.app.tool.R;
import com.viphuli.app.tool.adapter.ArrangeActionTypeAdapter;
import com.viphuli.app.tool.bean.part.ArrangeType;
import com.viphuli.app.tool.common.AccessTokenKeeper;
import com.viphuli.app.tool.http.ApiRequest;

/**
 * 加班类型
 * 
 * @author li.li
 *
 */
public class HolidayOverWorkTypeDialogFragment extends BaseProgressBottomDialogFragment implements OnItemClickListener {

	@Bind(R.id.id_listview)
	protected ListView listview;

	private ArrangeActionTypeAdapter adapter;

	private List<ArrangeType> list = new ArrayList<ArrangeType>();

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {

		Dialog dialog = super.onCreateDialog(savedInstanceState);
		dialog.setTitle("类型");//对话框标题

		return dialog;
	}

	@Override
	protected int obtainContentRes() {
		return R.layout.frag_holiday_over_work_type_dialog;
	}

	@Override
	protected void initParams() {

	}

	@Override
	protected void initView() {
		listview.setOnItemClickListener(this);
	}

	@Override
	protected void initData() {

		//获得排班分类信息
		AccessTokenKeeper tokenKeeper = AccessTokenKeeper.readAccessToken(getActivity());
		if (tokenKeeper.isLogin()) {

			RequestParams params = new RequestParams();
			params.put("circle_id", tokenKeeper.getUser().circleId());
			params.put("work_type", 2);//加班列表

			ApiRequest.holidayOverWorkTypeList.request(this, params, false);

		}

	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		
		//选择
		adapter.check(position);
		
		//赋值
		List<Integer> checkList = adapter.getCheck();
		ArrangeType arrangeType = list.get(checkList.iterator().next());
		HolidayOverWorkAddFragment frag = (HolidayOverWorkAddFragment) getParentFragment();
		frag.setArrangeType(arrangeType);
		
		//隐藏对话框
		getDialog().dismiss();

	}

	public ListView getListview() {
		return listview;
	}

	public List<ArrangeType> getList() {
		return list;
	}

	public void setAdapter(ArrangeActionTypeAdapter adapter) {
		this.adapter = adapter;
	}

	public ArrangeActionTypeAdapter getAdapter() {
		return adapter;
	}

}
